<?php
error_reporting(E_ALL & ~E_NOTICE);
ob_start();

include("../connect/connect.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Network Shop Management System</title>
<style type="text/css" >


body,td,th {
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 14px;
	text-align: center;
}
.ss {
	text-align: right;
}
.bbb {
	font-weight: bold;
}
body {
	background-color: #CCC;
}

@media print {
	input {
		display: none;
	}
}

</style>

</head>
<body>
<table width="400" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
  <tr>
    <td width="400" bgcolor="#FFFFFF">
    <p>
<?php
	$sql = "SELECT shop_name FROM shopname WHERE shop_id = '1'";
	$query = mysql_query($sql);
	$row = mysql_fetch_assoc($query);
	
	$dQuery = mysql_query("SELECT * FROM debtor WHERE deb_id = '".$_GET['id']."'");
	$dRow = mysql_fetch_array($dQuery);
?>
      <strong><font size="4"><?php echo $row["shop_name"]; ?></font></strong>
      </p>
      <p><strong><font size="4">ใบเสร็จรับเงิน</font></strong></p>
    <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><div align="left">วันที่ :  <?php $y=date("Y")+543; echo date("d/m/").$y; ?>&nbsp; เวลา : <?php echo date("H:i:s"); ?><br />
  <?php if($dRow["deb_name"]!=""){ ?>      ลูกค้า : <?php echo $dRow["deb_name"]; ?><br /><?php } ?>
  <?php if($dRow["deb_address"]!=""){ ?>        ที่อยู่ : <?php echo $dRow["deb_address"]; } ?></div></td>
      </tr>
    </table>
    <br />
    <table width="80%" height="21" style="border-bottom:dotted; border-bottom-color:#000; border-bottom-width:1px;border-top:dotted; border-top-color:#000; border-top-width:1px" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#666666">
      <tr align="center" bgcolor="#FFFFFF">
        <td><b>รายการ</b></td>
        <td width="15%"><b>จำนวน</b></td>
        <td width="19%"><b>ราคา</b></td>
        <td width="22%"><b>เป็นเงิน</b></td>
      </tr>
    </table>
    <table width="80%" height="21" style="border-bottom:dotted; border-bottom-color:#000; border-bottom-width:1px" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#666666">
      <?php

//============ ทำการแสงรายการที่ได้เลือกว่ามีกี่รายการ

$strNum=0;
$strTotal=0;
//============ เลือกว่ารายการสินค้าใดบ้าง
	$Query1 = "SELECT product.name as name,debtor_bill.quantity as quantity,debtor_bill.price as price FROM debtor_bill,product WHERE debtor_bill.product_id = product.product_id AND debtor_id = '".$_GET['id']."'";
	$dbquery1 = mysql_query($Query1);
	
	while($result = mysql_fetch_array($dbquery1)){
			$strNum++;
?>
      <tr align="center" bgcolor="#FFFFFF">
        <td><div align="left">
          <?php echo $result["name"];?>
        </div></td>
        <td width="15%"><div align="center">
          <?php echo $result["quantity"];?>
        </div></td>
        <td width="19%"><div align="center">
          <?php echo "".number_format($result["price"], 2,'.',',');?>
        </div></td>
        <td width="22%"><div align="right">
          <?php echo "".number_format(($result["price"])*$result["quantity"], 2,'.',',');?>
        </div></td>
      </tr>
      <?php $strTotal=$strTotal+(($result["price"])*$result["quantity"]);
}
?>
    </table>
    <table width="80%" height="21" style="border-bottom:double; border-bottom-color:#000; border-bottom-width:1px;" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#666666">
      <tr align="center" bgcolor="#FFFFFF">
        <td width="55%">&nbsp;</td>
        <td colspan="2"><div align="right">รวม&nbsp;&nbsp;
          <?php echo $strNum;?>
&nbsp;&nbsp;รายการ</div></td>
        </tr>
      <tr align="center" bgcolor="#FFFFFF" style="text-align: right">
        <td>&nbsp;</td>
        <td width="22%" align="right" class="ss">TOTAL</td>
        <td width="23%" class="bbb" style="text-align: right"><div align="right"><?php echo "".number_format($strTotal, 2,'.',',');?></div></td>
      </tr>
    </table>   
<p>ขอบคุณที่ใช้บริการ</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
<p>
</p>
<p>
  <input name="btnPrint" type="button" id="btnPrint" value="พิมพ์ใบเสร็จ" onClick="JavaScript:window.print();">
</p>
</body>
</html>
